package org.ly.service;

import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import org.ly.config.CustomConfig;
import org.ly.dao.HostMetric;
import org.ly.util.DateUtil;
import org.springframework.kafka.core.KafkaTemplate;
import org.springframework.stereotype.Component;

import java.sql.Timestamp;
import java.util.ArrayList;
import java.util.List;

@Component
public class KafkaProducerService {
    private final KafkaTemplate kafkaTemplate;
    private final CustomConfig customConfig;

    private static final Gson gson = new GsonBuilder().create();

    public KafkaProducerService(KafkaTemplate kafkaTemplate, CustomConfig customConfig) {
        this.kafkaTemplate = kafkaTemplate;
        this.customConfig = customConfig;
    }

    //发送消息方法
    public void send() {
        String outStr = "[{ \"COLLECTTIME\": \"2024-11-04 10:56:34\", \"COMPKEY\": \"127.0.0.1|testKey\", \"COMPTYPE\": \"000000\", \"HOSTIP\": \"192.168.0.11\", \"METRICCODE\": \"00000000000000\", \"METRICTYPE\": \"2\", \"METRICVALUE\": \"nodata\", \"SEQID\": \"0000000000000\", \"REPORTED\": false}],[{ \"COLLECTTIME\": \"2024-11-04 10:56:34\", \"COMPKEY\": \"127.0.0.1|testKey\", \"COMPTYPE\": \"000000\", \"HOSTIP\": \"192.168.0.1\", \"METRICCODE\": \"00000000000000\", \"METRICTYPE\": \"2\", \"METRICVALUE\": \"nodata\", \"SEQID\": \"0000000000000\", \"REPORTED\": false}],[{ \"COLLECTTIME\": \"2024-11-04 10:56:34\", \"COMPKEY\": \"127.0.0.1|testKey\", \"COMPTYPE\": \"000000\", \"HOSTIP\": \"192.168.0.2\", \"METRICCODE\": \"00000000000000\", \"METRICTYPE\": \"2\", \"METRICVALUE\": \"nodata\", \"SEQID\": \"0000000000000\", \"REPORTED\": false}],[{ \"COLLECTTIME\": \"2024-11-04 10:56:34\", \"COMPKEY\": \"127.0.0.1|testKey\", \"COMPTYPE\": \"000000\", \"HOSTIP\": \"192.168.0.3\", \"METRICCODE\": \"00000000000000\", \"METRICTYPE\": \"2\", \"METRICVALUE\": \"nodata\", \"SEQID\": \"0000000000000\", \"REPORTED\": false}],[{ \"COLLECTTIME\": \"2024-11-04 10:56:34\", \"COMPKEY\": \"127.0.0.1|testKey\", \"COMPTYPE\": \"000000\", \"HOSTIP\": \"192.168.0.4\", \"METRICCODE\": \"00000000000000\", \"METRICTYPE\": \"2\", \"METRICVALUE\": \"nodata\", \"SEQID\": \"0000000000000\", \"REPORTED\": false}]";
        kafkaTemplate.send(customConfig.getBeiXiangEopsMetricTopic(), outStr);
    }
}
